<?php
require_once "classdb.php";

// class user **********************************************************************************
class user extends db{
	private $table="user";
	public $id=NULL;
	public $username=NULL;
	public $password=NULL;
	public $hoten=NULL;
	public $diachi=NULL;
	public $dienthoai=NULL;
	public $email=NULL;
	public $ngay=NULL;
	public $thutu=-1;
	public $anhien=NULL;
	public $idgroup=NULL;
	
	function dt_set_id($id) { $this->id=$id; }
	function dt_set_username($username) { $this->username=$username; }
	function dt_set_password($password) { $this->password=$password; }
	function dt_set_hoten($hoten) { $this->hoten=$hoten; }
	function dt_set_diachi($diachi) { $this->diachi=$diachi; }
	function dt_set_dienthoai($dienthoai) { $this->dienthoai=$dienthoai; }
	function dt_set_email($email) { $this->email=$email; }
	function dt_set_ngay($ngay) { $this->ngay=$ngay; }
	function dt_set_thutu($thutu) { $this->thutu=$thutu; }
	function dt_set_anhien($anhien) { $this->anhien=$anhien; }
	function dt_set_idgroup($idgroup) { $this->idgroup=$idgroup; }
	
	
	function get_by_thutu($id=-1,$anhien=-1) {
        return $this->get_by_thutu_db($this->table,$id,$anhien);
	}
	function get_by_ngay($id=-1,$anhien=-1) {
		return $this->get_by_ngay_db($this->table,$id,$anhien);
	}
	function get_by_thutu_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_thutu_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_by_ngay_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_ngay_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_max_count($text="",$anhien=-1) {
        return $this->get_max_count_db($this->table,$text,$anhien);
	}
	function get_by_parent($table_parent,$field,$idparent) {
		return $this->get_by_parent_db($this->table,$table_parent,$field,$idparent);
	}
    
	function change_anhien($id) {
	   	$this->change_anhien_db($this->table,$id);
    }
	function change_anhien_list($listid) {
	   	$this->change_anhien_list_db($this->table,$listid);
    }
    
	function delete($id) {
		$this->delete_data_db($this->table,$id);
	}
	function delete_list($listid) {
		$this->delete_list_data_db($this->table,$listid);
	}
	
	function update_field($id,$field,$value,$anhien=-1) {
	   	$this->update_field_db($this->table,$id,$field,$value,$anhien);
    }
    
    /* 
    hàm update này chỉ dùng để update 1 đối tượng 
    được set dầy dủ các biến luôn cả "id" nhá
    Lưu ý: nếu ko set giá trị dầy đủ thi field nào ko set nó se~ ra null
    cho nen nếu mún update 1 filed thì nen xài hàm update_field() phía trên 
    dể update 1 field nhá  !!!!!!!
    */
	function update() {
		if ($this->id!=NULL && $this->id>0) {
			$list_field = $this->show_field_db($this->table);
			$query = "UPDATE ".$this->table." SET ";
			$flag = 0;
			foreach ($list_field as $field) {
                if ($flag == 1)
		    		$query = $query.$field[0]."='".$this->$field[0]."',";
		    	$flag = 1;
		    }
                    
		    $query = substr($query,0,strlen($query)-1);
			$query = $query." WHERE id='$this->id'";
			mysql_query($query) or die(mysql_error());
		}
    }
	
	function create() {
		// mún kiểm tra gì thì viết ở đây
		
		// code cứng không cần sửa **********************
		if ($this->thutu==-1)
			$this->thutu = $this->get_max_thutu_db($this->table)+1;
		$list_field = $this->show_field_db($this->table);
    	$query = "INSERT INTO ".$this->table." (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query.$field[0].",";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.") VALUES (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query."'".$this->$field[0]."',";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.")";
		mysql_query($query) or die(mysql_error());
		// ***********************************************
    }
    
	function get_by_username($username) {
		$query = "SELECT * FROM ".$this->table." WHERE username='$username'";
		return $this->get_data_db($query);
	}
	
	function get_by_ngay_admin() {
		$query = "SELECT * FROM ".$this->table." WHERE idgroup<>-1 order by ngay DESC";
		return $this->get_list_data_db($query);
	}
}

// class tin_theloai **********************************************************************************
class tin_theloai extends db{
	private $table="tin_theloai";
	public $id=NULL;
	public $ten_vi=NULL;
	public $ten_en=NULL;
	public $url_img=NULL;
	public $url_file=NULL;
	public $ngay=NULL;
	public $thutu=-1;
	public $anhien=NULL;
	public $id_root=NULL;
	
	function dt_set_id($id) { $this->id=$id; }
	function dt_set_ten_vi($ten_vi) { $this->ten_vi=$ten_vi; }
	function dt_set_ten_en($ten_en) { $this->ten_en=$ten_en; }
	function dt_set_url_img($url_img) { $this->url_img=$url_img; }
	function dt_set_url_file($url_file) { $this->url_file=$url_file; }
	function dt_set_ngay($ngay) { $this->ngay=$ngay; }
	function dt_set_thutu($thutu) { $this->thutu=$thutu; }
	function dt_set_anhien($anhien) { $this->anhien=$anhien; }
	function dt_set_id_root($id_root) { $this->id_root=$id_root; }
	
	
	function get_by_thutu($id=-1,$anhien=-1) {
        return $this->get_by_thutu_db($this->table,$id,$anhien);
	}
	function get_by_ngay($id=-1,$anhien=-1) {
		return $this->get_by_ngay_db($this->table,$id,$anhien);
	}
	function get_by_thutu_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_thutu_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_by_ngay_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_ngay_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_max_count($text="",$anhien=-1) {
        return $this->get_max_count_db($this->table,$text,$anhien);
	}
	function get_by_parent($table_parent,$field,$idparent) {
		return $this->get_by_parent_db($this->table,$table_parent,$field,$idparent);
	}
    
	function change_anhien($id) {
	   	$this->change_anhien_db($this->table,$id);
    }
	function change_anhien_list($listid) {
	   	$this->change_anhien_list_db($this->table,$listid);
    }
    
	function delete($id) {
		$this->delete_data_db($this->table,$id);
	}
	function delete_list($listid) {
		$this->delete_list_data_db($this->table,$listid);
	}
	
	function update_field($id,$field,$value,$anhien=-1) {
	   	$this->update_field_db($this->table,$id,$field,$value,$anhien);
    }
    
    /* 
    hàm update này chỉ dùng để update 1 đối tượng 
    được set dầy dủ các biến luôn cả "id" nhá
    Lưu ý: nếu ko set giá trị dầy đủ thi field nào ko set nó se~ ra null
    cho nen nếu mún update 1 filed thì nen xài hàm update_field() phía trên 
    dể update 1 field nhá  !!!!!!!
    */
	function update() {
		if ($this->id!=NULL && $this->id>0) {
			$list_field = $this->show_field_db($this->table);
			$query = "UPDATE ".$this->table." SET ";
			$flag = 0;
			foreach ($list_field as $field) {
                if ($flag == 1)
		    		$query = $query.$field[0]."='".$this->$field[0]."',";
		    	$flag = 1;
		    }
                    
		    $query = substr($query,0,strlen($query)-1);
			$query = $query." WHERE id='$this->id'";
			mysql_query($query) or die(mysql_error());
		}
    }
	
	function create() {
		// mún kiểm tra gì thì viết ở đây
		
		// code cứng không cần sửa **********************
		if ($this->thutu==-1)
			$this->thutu = $this->get_max_thutu_db($this->table)+1;
		$list_field = $this->show_field_db($this->table);
    	$query = "INSERT INTO ".$this->table." (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query.$field[0].",";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.") VALUES (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query."'".$this->$field[0]."',";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.")";
		mysql_query($query) or die(mysql_error());
		// ***********************************************
    }
	
}

// class tin_root **********************************************************************************
class tin_root extends db{
	private $table="tin_root";
	public $id=NULL;
	public $ten_vi=NULL;
	public $ten_en=NULL;
	public $ngay=NULL;
	public $thutu=-1;
	public $anhien=NULL;
	
	function dt_set_id($id) { $this->id=$id; }
	function dt_set_ten_vi($ten_vi) { $this->ten_vi=$ten_vi; }
	function dt_set_ten_en($ten_en) { $this->ten_en=$ten_en; }
	function dt_set_ngay($ngay) { $this->ngay=$ngay; }
	function dt_set_thutu($thutu) { $this->thutu=$thutu; }
	function dt_set_anhien($anhien) { $this->anhien=$anhien; }
	
	
	function get_by_thutu($id=-1,$anhien=-1) {
        return $this->get_by_thutu_db($this->table,$id,$anhien);
	}
	function get_by_ngay($id=-1,$anhien=-1) {
		return $this->get_by_ngay_db($this->table,$id,$anhien);
	}
	function get_by_thutu_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_thutu_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_by_ngay_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_ngay_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_max_count($text="",$anhien=-1) {
        return $this->get_max_count_db($this->table,$text,$anhien);
	}
	function get_by_parent($table_parent,$field,$idparent) {
		return $this->get_by_parent_db($this->table,$table_parent,$field,$idparent);
	}
    
	function change_anhien($id) {
	   	$this->change_anhien_db($this->table,$id);
    }
	function change_anhien_list($listid) {
	   	$this->change_anhien_list_db($this->table,$listid);
    }
    
	function delete($id) {
		$this->delete_data_db($this->table,$id);
	}
	function delete_list($listid) {
		$this->delete_list_data_db($this->table,$listid);
	}
	
	function update_field($id,$field,$value,$anhien=-1) {
	   	$this->update_field_db($this->table,$id,$field,$value,$anhien);
    }
    
    /* 
    hàm update này chỉ dùng để update 1 đối tượng 
    được set dầy dủ các biến luôn cả "id" nhá
    Lưu ý: nếu ko set giá trị dầy đủ thi field nào ko set nó se~ ra null
    cho nen nếu mún update 1 filed thì nen xài hàm update_field() phía trên 
    dể update 1 field nhá  !!!!!!!
    */
	function update() {
		if ($this->id!=NULL && $this->id>0) {
			$list_field = $this->show_field_db($this->table);
			$query = "UPDATE ".$this->table." SET ";
			$flag = 0;
			foreach ($list_field as $field) {
                if ($flag == 1)
		    		$query = $query.$field[0]."='".$this->$field[0]."',";
		    	$flag = 1;
		    }
                    
		    $query = substr($query,0,strlen($query)-1);
			$query = $query." WHERE id='$this->id'";
			mysql_query($query) or die(mysql_error());
		}
    }
	
	function create() {
		// mún kiểm tra gì thì viết ở đây
		
		// code cứng không cần sửa **********************
		if ($this->thutu==-1)
			$this->thutu = $this->get_max_thutu_db($this->table)+1;
		$list_field = $this->show_field_db($this->table);
    	$query = "INSERT INTO ".$this->table." (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query.$field[0].",";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.") VALUES (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query."'".$this->$field[0]."',";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.")";
		mysql_query($query) or die(mysql_error());
		// ***********************************************
    }
	
}

// class tin_loai **********************************************************************************
class tin_loai extends db{
	private $table="tin_loai";
	public $id=NULL;
	public $ten_vi=NULL;
	public $ten_en=NULL;
	public $noidung_vi=NULL;
	public $noidung_en=NULL;
	public $url_img=NULL;
	public $url_file=NULL;
	public $ngay=NULL;
	public $thutu=-1;
	public $anhien=NULL;
	public $idtl=NULL;
	public $id_root=NULL;
	
	function dt_set_id($id) { $this->id=$id; }
	function dt_set_ten_vi($ten_vi) { $this->ten_vi=$ten_vi; }
	function dt_set_ten_en($ten_en) { $this->ten_en=$ten_en; }
	function dt_set_noidung_vi($noidung_vi) { $this->noidung_vi=$noidung_vi; }
	function dt_set_noidung_en($noidung_en) { $this->noidung_en=$noidung_en; }
	function dt_set_url_img($url_img) { $this->url_img=$url_img; }
	function dt_set_url_file($url_file) { $this->url_file=$url_file; }
	function dt_set_ngay($ngay) { $this->ngay=$ngay; }
	function dt_set_thutu($thutu) { $this->thutu=$thutu; }
	function dt_set_anhien($anhien) { $this->anhien=$anhien; }
	function dt_set_idtl($idtl) { $this->idtl=$idtl; }
	function dt_set_id_root($id_root) { $this->id_root=$id_root; }
	
	
	function get_by_thutu($id=-1,$anhien=-1) {
        return $this->get_by_thutu_db($this->table,$id,$anhien);
	}
	function get_by_ngay($id=-1,$anhien=-1) {
		return $this->get_by_ngay_db($this->table,$id,$anhien);
	}
	function get_by_thutu_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_thutu_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_by_ngay_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_ngay_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_max_count($text="",$anhien=-1) {
        return $this->get_max_count_db($this->table,$text,$anhien);
	}
	function get_by_parent($table_parent,$field,$idparent) {
		return $this->get_by_parent_db($this->table,$table_parent,$field,$idparent);
	}
    
	function change_anhien($id) {
	   	$this->change_anhien_db($this->table,$id);
    }
	function change_anhien_list($listid) {
	   	$this->change_anhien_list_db($this->table,$listid);
    }
    
	function delete($id) {
		$this->delete_data_db($this->table,$id);
	}
	function delete_list($listid) {
		$this->delete_list_data_db($this->table,$listid);
	}
	
	function update_field($id,$field,$value,$anhien=-1) {
	   	$this->update_field_db($this->table,$id,$field,$value,$anhien);
    }
    
    /* 
    hàm update này chỉ dùng để update 1 đối tượng 
    được set dầy dủ các biến luôn cả "id" nhá
    Lưu ý: nếu ko set giá trị dầy đủ thi field nào ko set nó se~ ra null
    cho nen nếu mún update 1 filed thì nen xài hàm update_field() phía trên 
    dể update 1 field nhá  !!!!!!!
    */
	function update() {
		if ($this->id!=NULL && $this->id>0) {
			$list_field = $this->show_field_db($this->table);
			$query = "UPDATE ".$this->table." SET ";
			$flag = 0;
			foreach ($list_field as $field) {
                if ($flag == 1)
		    		$query = $query.$field[0]."='".$this->$field[0]."',";
		    	$flag = 1;
		    }
                    
		    $query = substr($query,0,strlen($query)-1);
			$query = $query." WHERE id='$this->id'";
			mysql_query($query) or die(mysql_error());
		}
    }
	
	function create() {
		// mún kiểm tra gì thì viết ở đây
		
		// code cứng không cần sửa **********************
		if ($this->thutu==-1)
			$this->thutu = $this->get_max_thutu_db($this->table)+1;
		$list_field = $this->show_field_db($this->table);
    	$query = "INSERT INTO ".$this->table." (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query.$field[0].",";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.") VALUES (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query."'".$this->$field[0]."',";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.")";
		mysql_query($query) or die(mysql_error());
		// ***********************************************
    }	
	
}

// class tin **********************************************************************************
class tin extends db{
	private $table="tin";
	public $id=NULL;
	public $gia_vi=NULL;
	public $ten_vi=NULL;
	public $tomtat_vi=NULL;
	public $noidung_ct_vi=NULL;
	public $noidung_gia_vi=NULL;
	public $noidung_dk_vi=NULL;
	public $noidung_lh_vi=NULL;
	public $gia_en=NULL;
	public $ten_en=NULL;
	public $tomtat_en=NULL;
	public $noidung_ct_en=NULL;
	public $noidung_gia_en=NULL;
	public $noidung_dk_en=NULL;
	public $noidung_lh_en=NULL;
	public $noidung_img=NULL;
	public $url_img=NULL;
	public $url_file=NULL;
	public $ngay=NULL;
	public $thutu=-1;
	public $anhien=NULL;
	public $idtl=NULL;
	public $idloai=NULL;
	public $id_root=NULL;
	
	function dt_set_id($id) { $this->id=$id; }
	function dt_set_gia_vi($gia_vi) { $this->gia_vi=$gia_vi; }
	function dt_set_ten_vi($ten_vi) { $this->ten_vi=$ten_vi; }
	function dt_set_tomtat_vi($tomtat_vi) { $this->tomtat_vi=$tomtat_vi; }
	function dt_set_noidung_ct_vi($noidung_ct_vi) { $this->noidung_ct_vi=$noidung_ct_vi; }
	function dt_set_noidung_gia_vi($noidung_gia_vi) { $this->noidung_gia_vi=$noidung_gia_vi; }
	function dt_set_noidung_dk_vi($noidung_dk_vi) { $this->noidung_dk_vi=$noidung_dk_vi; }
	function dt_set_noidung_lh_vi($noidung_lh_vi) { $this->noidung_lh_vi=$noidung_lh_vi; }
	function dt_set_gia_en($gia_en) { $this->gia_en=$gia_en; }
	function dt_set_ten_en($ten_en) { $this->ten_en=$ten_en; }
	function dt_set_tomtat_en($tomtat_en) { $this->tomtat_en=$tomtat_en; }
	function dt_set_noidung_ct_en($noidung_ct_en) { $this->noidung_ct_en=$noidung_ct_en; }
	function dt_set_noidung_gia_en($noidung_gia_en) { $this->noidung_gia_en=$noidung_gia_en; }
	function dt_set_noidung_dk_en($noidung_dk_en) { $this->noidung_dk_en=$noidung_dk_en; }
	function dt_set_noidung_lh_en($noidung_lh_en) { $this->noidung_lh_en=$noidung_lh_en; }
	function dt_set_noidung_img($noidung_img) { $this->noidung_img=$noidung_img; }
	function dt_set_url_img($url_img) { $this->url_img=$url_img; }
	function dt_set_url_file($url_file) { $this->url_file=$url_file; }
	function dt_set_ngay($ngay) { $this->ngay=$ngay; }
	function dt_set_thutu($thutu) { $this->thutu=$thutu; }
	function dt_set_anhien($anhien) { $this->anhien=$anhien; }
	function dt_set_idtl($idtl) { $this->idtl=$idtl; }
	function dt_set_idloai($idloai) { $this->idloai=$idloai; }
	function dt_set_id_root($id_root) { $this->id_root=$id_root; }
	
	
	function get_by_thutu($id=-1,$anhien=-1) {
        return $this->get_by_thutu_db($this->table,$id,$anhien);
	}
	function get_by_ngay($id=-1,$anhien=-1) {
		return $this->get_by_ngay_db($this->table,$id,$anhien);
	}
	function get_by_thutu_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_thutu_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_by_ngay_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_ngay_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_max_count($text="",$anhien=-1) {
        return $this->get_max_count_db($this->table,$text,$anhien);
	}
	function get_by_parent($table_parent,$field,$idparent) {
		return $this->get_by_parent_db($this->table,$table_parent,$field,$idparent);
	}
    
	function change_anhien($id) {
	   	$this->change_anhien_db($this->table,$id);
    }
	function change_anhien_list($listid) {
	   	$this->change_anhien_list_db($this->table,$listid);
    }
    
	function delete($id) {
		$this->delete_data_db($this->table,$id);
	}
	function delete_list($listid) {
		$this->delete_list_data_db($this->table,$listid);
	}
	
	function update_field($id,$field,$value,$anhien=-1) {
	   	$this->update_field_db($this->table,$id,$field,$value,$anhien);
    }
    
    /* 
    hàm update này chỉ dùng để update 1 đối tượng 
    được set dầy dủ các biến luôn cả "id" nhá
    Lưu ý: nếu ko set giá trị dầy đủ thi field nào ko set nó se~ ra null
    cho nen nếu mún update 1 filed thì nen xài hàm update_field() phía trên 
    dể update 1 field nhá  !!!!!!!
    */
	function update() {
		if ($this->id!=NULL && $this->id>0) {
			$list_field = $this->show_field_db($this->table);
			$query = "UPDATE ".$this->table." SET ";
			$flag = 0;
			foreach ($list_field as $field) {
                if ($flag == 1)
		    		$query = $query.$field[0]."='".$this->$field[0]."',";
		    	$flag = 1;
		    }
                    
		    $query = substr($query,0,strlen($query)-1);
			$query = $query." WHERE id='$this->id'";
			mysql_query($query) or die(mysql_error());
		}
    }
	
	function create() {
		// mún kiểm tra gì thì viết ở đây
		
		// code cứng không cần sửa **********************
		if ($this->thutu==-1)
			$this->thutu = $this->get_max_thutu_db($this->table)+1;
		$list_field = $this->show_field_db($this->table);
    	$query = "INSERT INTO ".$this->table." (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query.$field[0].",";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.") VALUES (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query."'".$this->$field[0]."',";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.")";
        //echo $query;die;
		mysql_query($query) or die(mysql_error());
		// ***********************************************
    }
	
	
	
	// A E nào mún viết hàm mới thì dựa vào 2 demo dưới day nhá
	//TRuy van list du~ lieu
	function ham_demo($ten) {
		$query = "SELECT * FROM ".$this->table." WHERE ten_vi like '%".$ten."%' order by ngay DESC";
		return $this->get_list_data_db($query);
	}
	//TRuy van 1 phan tu
	function ham_demo2($id) {
		$query = "SELECT * FROM ".$this->table." WHERE id='$id'";
		return $this->get_data_db($query);
	}
	//Thuc hien 1 xử lý
	function ham_demo3($id) {
		$query = "DELETE FROM ".$this->table." WHERE id='$id'";
		mysql_query($query) or die(mysql_error());
	}
	
}

// class sanpham_loai **********************************************************************************
class sanpham_loai extends db{
	private $table="sanpham_loai";
	public $id=NULL;
	public $ten_vi=NULL;
	public $ten_en=NULL;
	public $noidung_vi=NULL;
	public $noidung_en=NULL;
	public $url_img=NULL;
	public $url_file=NULL;
	public $ngay=NULL;
	public $thutu=-1;
	public $anhien=NULL;
	public $idcl=NULL;
	
	function dt_set_id($id) { $this->id=$id; }
	function dt_set_ten_vi($ten_vi) { $this->ten_vi=$ten_vi; }
	function dt_set_ten_en($ten_en) { $this->ten_en=$ten_en; }
	function dt_set_noidung_vi($noidung_vi) { $this->noidung_vi=$noidung_vi; }
	function dt_set_noidung_en($noidung_en) { $this->noidung_en=$noidung_en; }
	function dt_set_url_img($url_img) { $this->url_img=$url_img; }
	function dt_set_url_file($url_file) { $this->url_file=$url_file; }
	function dt_set_ngay($ngay) { $this->ngay=$ngay; }
	function dt_set_thutu($thutu) { $this->thutu=$thutu; }
	function dt_set_anhien($anhien) { $this->anhien=$anhien; }
	function dt_set_idcl($idcl) { $this->idcl=$idcl; }
	
	
	function get_by_thutu($id=-1,$anhien=-1) {
        return $this->get_by_thutu_db($this->table,$id,$anhien);
	}
	function get_by_ngay($id=-1,$anhien=-1) {
		return $this->get_by_ngay_db($this->table,$id,$anhien);
	}
	function get_by_thutu_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_thutu_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_by_ngay_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_ngay_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_max_count($text="",$anhien=-1) {
        return $this->get_max_count_db($this->table,$text,$anhien);
	}
	function get_by_parent($table_parent,$field,$idparent) {
		return $this->get_by_parent_db($this->table,$table_parent,$field,$idparent);
	}
    
	function change_anhien($id) {
	   	$this->change_anhien_db($this->table,$id);
    }
	function change_anhien_list($listid) {
	   	$this->change_anhien_list_db($this->table,$listid);
    }
    
	function delete($id) {
		$this->delete_data_db($this->table,$id);
	}
	function delete_list($listid) {
		$this->delete_list_data_db($this->table,$listid);
	}
	
	function update_field($id,$field,$value,$anhien=-1) {
	   	$this->update_field_db($this->table,$id,$field,$value,$anhien);
    }
    
    /* 
    hàm update này chỉ dùng để update 1 đối tượng 
    được set dầy dủ các biến luôn cả "id" nhá
    Lưu ý: nếu ko set giá trị dầy đủ thi field nào ko set nó se~ ra null
    cho nen nếu mún update 1 filed thì nen xài hàm update_field() phía trên 
    dể update 1 field nhá  !!!!!!!
    */
	function update() {
		if ($this->id!=NULL && $this->id>0) {
			$list_field = $this->show_field_db($this->table);
			$query = "UPDATE ".$this->table." SET ";
			$flag = 0;
			foreach ($list_field as $field) {
                if ($flag == 1)
		    		$query = $query.$field[0]."='".$this->$field[0]."',";
		    	$flag = 1;
		    }
                    
		    $query = substr($query,0,strlen($query)-1);
			$query = $query." WHERE id='$this->id'";
			mysql_query($query) or die(mysql_error());
		}
    }
	
	function create() {
		// mún kiểm tra gì thì viết ở đây
		
		// code cứng không cần sửa **********************
		if ($this->thutu==-1)
			$this->thutu = $this->get_max_thutu_db($this->table)+1;
		$list_field = $this->show_field_db($this->table);
    	$query = "INSERT INTO ".$this->table." (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query.$field[0].",";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.") VALUES (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query."'".$this->$field[0]."',";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.")";
		mysql_query($query) or die(mysql_error());
		// ***********************************************
    }
	
}

// class sanpham_chungloai **********************************************************************************
class sanpham_chungloai extends db{
	private $table="sanpham_chungloai";
	public $id=NULL;
	public $ten_vi=NULL;
	public $ten_en=NULL;
	public $url_img=NULL;
	public $url_file=NULL;
	public $ngay=NULL;
	public $thutu=-1;
	public $anhien=NULL;
	
	function dt_set_id($id) { $this->id=$id; }
	function dt_set_ten_vi($ten_vi) { $this->ten_vi=$ten_vi; }
	function dt_set_ten_en($ten_en) { $this->ten_en=$ten_en; }
	function dt_set_url_img($url_img) { $this->url_img=$url_img; }
	function dt_set_url_file($url_file) { $this->url_file=$url_file; }
	function dt_set_ngay($ngay) { $this->ngay=$ngay; }
	function dt_set_thutu($thutu) { $this->thutu=$thutu; }
	function dt_set_anhien($anhien) { $this->anhien=$anhien; }
	
	
	function get_by_thutu($id=-1,$anhien=-1) {
        return $this->get_by_thutu_db($this->table,$id,$anhien);
	}
	function get_by_ngay($id=-1,$anhien=-1) {
		return $this->get_by_ngay_db($this->table,$id,$anhien);
	}
	function get_by_thutu_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_thutu_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_by_ngay_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_ngay_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_max_count($text="",$anhien=-1) {
        return $this->get_max_count_db($this->table,$text,$anhien);
	}
	function get_by_parent($table_parent,$field,$idparent) {
		return $this->get_by_parent_db($this->table,$table_parent,$field,$idparent);
	}
    
	function change_anhien($id) {
	   	$this->change_anhien_db($this->table,$id);
    }
	function change_anhien_list($listid) {
	   	$this->change_anhien_list_db($this->table,$listid);
    }
    
	function delete($id) {
		$this->delete_data_db($this->table,$id);
	}
	function delete_list($listid) {
		$this->delete_list_data_db($this->table,$listid);
	}
	
	function update_field($id,$field,$value,$anhien=-1) {
	   	$this->update_field_db($this->table,$id,$field,$value,$anhien);
    }
    
    /* 
    hàm update này chỉ dùng để update 1 đối tượng 
    được set dầy dủ các biến luôn cả "id" nhá
    Lưu ý: nếu ko set giá trị dầy đủ thi field nào ko set nó se~ ra null
    cho nen nếu mún update 1 filed thì nen xài hàm update_field() phía trên 
    dể update 1 field nhá  !!!!!!!
    */
	function update() {
		if ($this->id!=NULL && $this->id>0) {
			$list_field = $this->show_field_db($this->table);
			$query = "UPDATE ".$this->table." SET ";
			$flag = 0;
			foreach ($list_field as $field) {
                if ($flag == 1)
		    		$query = $query.$field[0]."='".$this->$field[0]."',";
		    	$flag = 1;
		    }
                    
		    $query = substr($query,0,strlen($query)-1);
			$query = $query." WHERE id='$this->id'";
			mysql_query($query) or die(mysql_error());
		}
    }
	
	function create() {
		// mún kiểm tra gì thì viết ở đây
		
		// code cứng không cần sửa **********************
		if ($this->thutu==-1)
			$this->thutu = $this->get_max_thutu_db($this->table)+1;
		$list_field = $this->show_field_db($this->table);
    	$query = "INSERT INTO ".$this->table." (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query.$field[0].",";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.") VALUES (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query."'".$this->$field[0]."',";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.")";
		mysql_query($query) or die(mysql_error());
		// ***********************************************
    }
	
}

// class sanpham **********************************************************************************
class sanpham extends db{
	private $table="sanpham";
	public $id=NULL;
	public $ten_vi=NULL;
	public $ten_en=NULL;
	public $tomtat_vi=NULL;
	public $tomtat_en=NULL;
	public $noidung_vi=NULL;
	public $noidung_en=NULL;
	public $gia=NULL;
	public $url_img=NULL;
	public $url_file=NULL;
	public $ngay=NULL;
	public $thutu=-1;
	public $anhien=NULL;
	public $idcl=NULL;
	public $idloai=NULL;
	
	function dt_set_id($id) { $this->id=$id; }
	function dt_set_ten_vi($ten_vi) { $this->ten_vi=$ten_vi; }
	function dt_set_ten_en($ten_en) { $this->ten_en=$ten_en; }
	function dt_set_tomtat_vi($tomtat_vi) { $this->tomtat_vi=$tomtat_vi; }
	function dt_set_tomtat_en($tomtat_en) { $this->tomtat_en=$tomtat_en; }
	function dt_set_noidung_vi($noidung_vi) { $this->noidung_vi=$noidung_vi; }
	function dt_set_noidung_en($noidung_en) { $this->noidung_en=$noidung_en; }
	function dt_set_gia($gia) { $this->gia=$gia; }
	function dt_set_url_img($url_img) { $this->url_img=$url_img; }
	function dt_set_url_file($url_file) { $this->url_file=$url_file; }
	function dt_set_ngay($ngay) { $this->ngay=$ngay; }
	function dt_set_thutu($thutu) { $this->thutu=$thutu; }
	function dt_set_anhien($anhien) { $this->anhien=$anhien; }
	function dt_set_idcl($idcl) { $this->idcl=$idcl; }
	function dt_set_idloai($idloai) { $this->idloai=$idloai; }
	
	
	function get_by_thutu($id=-1,$anhien=-1) {
        return $this->get_by_thutu_db($this->table,$id,$anhien);
	}
	function get_by_ngay($id=-1,$anhien=-1) {
		return $this->get_by_ngay_db($this->table,$id,$anhien);
	}
	function get_by_thutu_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_thutu_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_by_ngay_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_ngay_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_max_count($text="",$anhien=-1) {
        return $this->get_max_count_db($this->table,$text,$anhien);
	}
	function get_by_parent($table_parent,$field,$idparent) {
		return $this->get_by_parent_db($this->table,$table_parent,$field,$idparent);
	}
    
	function change_anhien($id) {
	   	$this->change_anhien_db($this->table,$id);
    }
	function change_anhien_list($listid) {
	   	$this->change_anhien_list_db($this->table,$listid);
    }
    
	function delete($id) {
		$this->delete_data_db($this->table,$id);
	}
	function delete_list($listid) {
		$this->delete_list_data_db($this->table,$listid);
	}
	
	function update_field($id,$field,$value,$anhien=-1) {
	   	$this->update_field_db($this->table,$id,$field,$value,$anhien);
    }
    
    /* 
    hàm update này chỉ dùng để update 1 đối tượng 
    được set dầy dủ các biến luôn cả "id" nhá
    Lưu ý: nếu ko set giá trị dầy đủ thi field nào ko set nó se~ ra null
    cho nen nếu mún update 1 filed thì nen xài hàm update_field() phía trên 
    dể update 1 field nhá  !!!!!!!
    */
	function update() {
		if ($this->id!=NULL && $this->id>0) {
			$list_field = $this->show_field_db($this->table);
			$query = "UPDATE ".$this->table." SET ";
			$flag = 0;
			foreach ($list_field as $field) {
                if ($flag == 1)
		    		$query = $query.$field[0]."='".$this->$field[0]."',";
		    	$flag = 1;
		    }
                    
		    $query = substr($query,0,strlen($query)-1);
			$query = $query." WHERE id='$this->id'";
			mysql_query($query) or die(mysql_error());
		}
    }
	
	function create() {
		// mún kiểm tra gì thì viết ở đây
		
		// code cứng không cần sửa **********************
		if ($this->thutu==-1)
			$this->thutu = $this->get_max_thutu_db($this->table)+1;
		$list_field = $this->show_field_db($this->table);
    	$query = "INSERT INTO ".$this->table." (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query.$field[0].",";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.") VALUES (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query."'".$this->$field[0]."',";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.")";
		mysql_query($query) or die(mysql_error());
		// ***********************************************
    }
	
}

// class lienhe **********************************************************************************
class lienhe extends db{
	private $table="lienhe";
	public $id=NULL;
	public $ten_vi=NULL;
	public $ten_en=NULL;
	public $sdt=NULL;
	public $nick_yahoo=NULL;
	public $nick_skype=NULL;
	public $url_img=NULL;
	public $url_file=NULL;
	public $ngay=NULL;
	public $thutu=-1;
	public $anhien=NULL;
	
	function dt_set_id($id) { $this->id=$id; }
	function dt_set_ten_vi($ten_vi) { $this->ten_vi=$ten_vi; }
	function dt_set_ten_en($ten_en) { $this->ten_en=$ten_en; }
	function dt_set_sdt($sdt) { $this->sdt=$sdt; }
	function dt_set_nick_yahoo($nick_yahoo) { $this->nick_yahoo=$nick_yahoo; }
	function dt_set_nick_skype($nick_skype) { $this->nick_skype=$nick_skype; }
	function dt_set_url_img($url_img) { $this->url_img=$url_img; }
	function dt_set_url_file($url_file) { $this->url_file=$url_file; }
	function dt_set_ngay($ngay) { $this->ngay=$ngay; }
	function dt_set_thutu($thutu) { $this->thutu=$thutu; }
	function dt_set_anhien($anhien) { $this->anhien=$anhien; }
	
	
	function get_by_thutu($id=-1,$anhien=-1) {
        return $this->get_by_thutu_db($this->table,$id,$anhien);
	}
	function get_by_ngay($id=-1,$anhien=-1) {
		return $this->get_by_ngay_db($this->table,$id,$anhien);
	}
	function get_by_thutu_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_thutu_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_by_ngay_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_ngay_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_max_count($text="",$anhien=-1) {
        return $this->get_max_count_db($this->table,$text,$anhien);
	}
	function get_by_parent($table_parent,$field,$idparent) {
		return $this->get_by_parent_db($this->table,$table_parent,$field,$idparent);
	}
    
	function change_anhien($id) {
	   	$this->change_anhien_db($this->table,$id);
    }
	function change_anhien_list($listid) {
	   	$this->change_anhien_list_db($this->table,$listid);
    }
    
	function delete($id) {
		$this->delete_data_db($this->table,$id);
	}
	function delete_list($listid) {
		$this->delete_list_data_db($this->table,$listid);
	}
	
	function update_field($id,$field,$value,$anhien=-1) {
	   	$this->update_field_db($this->table,$id,$field,$value,$anhien);
    }
    
    /* 
    hàm update này chỉ dùng để update 1 đối tượng 
    được set dầy dủ các biến luôn cả "id" nhá
    Lưu ý: nếu ko set giá trị dầy đủ thi field nào ko set nó se~ ra null
    cho nen nếu mún update 1 filed thì nen xài hàm update_field() phía trên 
    dể update 1 field nhá  !!!!!!!
    */
	function update() {
		if ($this->id!=NULL && $this->id>0) {
			$list_field = $this->show_field_db($this->table);
			$query = "UPDATE ".$this->table." SET ";
			$flag = 0;
			foreach ($list_field as $field) {
                if ($flag == 1)
		    		$query = $query.$field[0]."='".$this->$field[0]."',";
		    	$flag = 1;
		    }
                    
		    $query = substr($query,0,strlen($query)-1);
			$query = $query." WHERE id='$this->id'";
			mysql_query($query) or die(mysql_error());
		}
    }
	
	function create() {
		// mún kiểm tra gì thì viết ở đây
		
		// code cứng không cần sửa **********************
		if ($this->thutu==-1)
			$this->thutu = $this->get_max_thutu_db($this->table)+1;
		$list_field = $this->show_field_db($this->table);
    	$query = "INSERT INTO ".$this->table." (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query.$field[0].",";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.") VALUES (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query."'".$this->$field[0]."',";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.")";
		mysql_query($query) or die(mysql_error());
		// ***********************************************
    }
	
}

// class thuvienanh **********************************************************************************
class thuvienanh extends db{
	private $table="thuvienanh";
	public $id=NULL;
	public $ten_vi=NULL;
	public $ten_en=NULL;
	public $url_img=NULL;
	public $url_file=NULL;
	public $ngay=NULL;
	public $thutu=-1;
	public $anhien=NULL;
	public $loai=NULL;
	
	function dt_set_id($id) { $this->id=$id; }
	function dt_set_ten_vi($ten_vi) { $this->ten_vi=$ten_vi; }
	function dt_set_ten_en($ten_en) { $this->ten_en=$ten_en; }
	function dt_set_url_img($url_img) { $this->url_img=$url_img; }
	function dt_set_url_file($url_file) { $this->url_file=$url_file; }
	function dt_set_ngay($ngay) { $this->ngay=$ngay; }
	function dt_set_thutu($thutu) { $this->thutu=$thutu; }
	function dt_set_anhien($anhien) { $this->anhien=$anhien; }
	function dt_set_loai($loai) { $this->loai=$loai; }
	
	
	function get_by_thutu($id=-1,$anhien=-1) {
        return $this->get_by_thutu_db($this->table,$id,$anhien);
	}
	function get_by_ngay($id=-1,$anhien=-1) {
		return $this->get_by_ngay_db($this->table,$id,$anhien);
	}
	function get_by_thutu_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_thutu_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_by_ngay_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_ngay_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_max_count($text="",$anhien=-1) {
        return $this->get_max_count_db($this->table,$text,$anhien);
	}
	function get_by_parent($table_parent,$field,$idparent) {
		return $this->get_by_parent_db($this->table,$table_parent,$field,$idparent);
	}
    
	function change_anhien($id) {
	   	$this->change_anhien_db($this->table,$id);
    }
	function change_anhien_list($listid) {
	   	$this->change_anhien_list_db($this->table,$listid);
    }
    
	function delete($id) {
		$this->delete_data_db($this->table,$id);
	}
	function delete_list($listid) {
		$this->delete_list_data_db($this->table,$listid);
	}
	
	function update_field($id,$field,$value,$anhien=-1) {
	   	$this->update_field_db($this->table,$id,$field,$value,$anhien);
    }
    
    /* 
    hàm update này chỉ dùng để update 1 đối tượng 
    được set dầy dủ các biến luôn cả "id" nhá
    Lưu ý: nếu ko set giá trị dầy đủ thi field nào ko set nó se~ ra null
    cho nen nếu mún update 1 filed thì nen xài hàm update_field() phía trên 
    dể update 1 field nhá  !!!!!!!
    */
	function update() {
		if ($this->id!=NULL && $this->id>0) {
			$list_field = $this->show_field_db($this->table);
			$query = "UPDATE ".$this->table." SET ";
			$flag = 0;
			foreach ($list_field as $field) {
                if ($flag == 1)
		    		$query = $query.$field[0]."='".$this->$field[0]."',";
		    	$flag = 1;
		    }
                    
		    $query = substr($query,0,strlen($query)-1);
			$query = $query." WHERE id='$this->id'";
			mysql_query($query) or die(mysql_error());
		}
    }
	
	function create() {
		// mún kiểm tra gì thì viết ở đây
		
		// code cứng không cần sửa **********************
		if ($this->thutu==-1)
			$this->thutu = $this->get_max_thutu_db($this->table)+1;
		$list_field = $this->show_field_db($this->table);
    	$query = "INSERT INTO ".$this->table." (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query.$field[0].",";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.") VALUES (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query."'".$this->$field[0]."',";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.")";
		mysql_query($query) or die(mysql_error());
		// ***********************************************
    }
	
}

// class tin_tonghop **********************************************************************************
class tin_tonghop extends db{
	private $table="tin_tonghop";
	public $id=NULL;
	public $ten_vi=NULL;
	public $ten_en=NULL;
	public $tomtat_vi=NULL;
	public $tomtat_en=NULL;
	public $noidung_vi=NULL;
	public $noidung_en=NULL;
	public $url_img=NULL;
	public $url_file=NULL;
	public $ngay=NULL;
	public $thutu=-1;
	public $anhien=NULL;
	public $idgroup=NULL;
	
	function dt_set_id($id) { $this->id=$id; }
	function dt_set_ten_vi($ten_vi) { $this->ten_vi=$ten_vi; }
	function dt_set_ten_en($ten_en) { $this->ten_en=$ten_en; }
	function dt_set_tomtat_vi($tomtat_vi) { $this->tomtat_vi=$tomtat_vi; }
	function dt_set_tomtat_en($tomtat_en) { $this->tomtat_en=$tomtat_en; }
	function dt_set_noidung_vi($noidung_vi) { $this->noidung_vi=$noidung_vi; }
	function dt_set_noidung_en($noidung_en) { $this->noidung_en=$noidung_en; }	
	function dt_set_url_img($url_img) { $this->url_img=$url_img; }
	function dt_set_url_file($url_file) { $this->url_file=$url_file; }
	function dt_set_ngay($ngay) { $this->ngay=$ngay; }
	function dt_set_thutu($thutu) { $this->thutu=$thutu; }
	function dt_set_anhien($anhien) { $this->anhien=$anhien; }
	function dt_set_idgroup($idgroup) { $this->idgroup=$idgroup; }
	
	
	function get_by_thutu($id=-1,$anhien=-1) {
        return $this->get_by_thutu_db($this->table,$id,$anhien);
	}
	function get_by_ngay($id=-1,$anhien=-1) {
		return $this->get_by_ngay_db($this->table,$id,$anhien);
	}
	function get_by_thutu_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_thutu_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_by_ngay_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_ngay_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_max_count($text="",$anhien=-1) {
        return $this->get_max_count_db($this->table,$text,$anhien);
	}
	function get_by_parent($table_parent,$field,$idparent) {
		return $this->get_by_parent_db($this->table,$table_parent,$field,$idparent);
	}
    
	function change_anhien($id) {
	   	$this->change_anhien_db($this->table,$id);
    }
	function change_anhien_list($listid) {
	   	$this->change_anhien_list_db($this->table,$listid);
    }
    
	function delete($id) {
		$this->delete_data_db($this->table,$id);
	}
	function delete_list($listid) {
		$this->delete_list_data_db($this->table,$listid);
	}
	
	function update_field($id,$field,$value,$anhien=-1) {
	   	$this->update_field_db($this->table,$id,$field,$value,$anhien);
    }
    
    /* 
    hàm update này chỉ dùng để update 1 đối tượng 
    được set dầy dủ các biến luôn cả "id" nhá
    Lưu ý: nếu ko set giá trị dầy đủ thi field nào ko set nó se~ ra null
    cho nen nếu mún update 1 filed thì nen xài hàm update_field() phía trên 
    dể update 1 field nhá  !!!!!!!
    */
	function update() {
		if ($this->id!=NULL && $this->id>0) {
			$list_field = $this->show_field_db($this->table);
			$query = "UPDATE ".$this->table." SET ";
			$flag = 0;
			foreach ($list_field as $field) {
                if ($flag == 1)
		    		$query = $query.$field[0]."='".$this->$field[0]."',";
		    	$flag = 1;
		    }
                    
		    $query = substr($query,0,strlen($query)-1);
			$query = $query." WHERE id='$this->id'";
			mysql_query($query) or die(mysql_error());
		}
    }
	
	function create() {
		// mún kiểm tra gì thì viết ở đây
		
		// code cứng không cần sửa **********************
		if ($this->thutu==-1)
			$this->thutu = $this->get_max_thutu_db($this->table)+1;
		$list_field = $this->show_field_db($this->table);
    	$query = "INSERT INTO ".$this->table." (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query.$field[0].",";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.") VALUES (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query."'".$this->$field[0]."',";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.")";
		mysql_query($query) or die(mysql_error());
		// ***********************************************
    }
	
}

// class field **********************************************************************************
class field extends db{
	private $table="field";
	public $id=NULL;
	public $ten_vi=NULL;
	public $ten_en=NULL;
	public $content_vi=NULL;
	public $content_en=NULL;
	public $tieude=NULL;
	public $url_img=NULL;
	public $url_file=NULL;
	public $ngay=NULL;
	public $thutu=-1;
	public $anhien=NULL;
	public $idgroup=NULL;
	
	function dt_set_id($id) { $this->id=$id; }
	function dt_set_ten_vi($ten_vi) { $this->ten_vi=$ten_vi; }
	function dt_set_ten_en($ten_en) { $this->ten_en=$ten_en; }
	function dt_set_content_vi($content_vi) { $this->content_vi=$content_vi; }
	function dt_set_content_en($content_en) { $this->content_en=$content_en; }	
	function dt_set_tieude($tieude) { $this->tieude=$tieude; }	
	function dt_set_url_img($url_img) { $this->url_img=$url_img; }
	function dt_set_url_file($url_file) { $this->url_file=$url_file; }
	function dt_set_ngay($ngay) { $this->ngay=$ngay; }
	function dt_set_thutu($thutu) { $this->thutu=$thutu; }
	function dt_set_anhien($anhien) { $this->anhien=$anhien; }
	function dt_set_idgroup($idgroup) { $this->idgroup=$idgroup; }
	
	
	function get_by_thutu($id=-1,$anhien=-1) {
        return $this->get_by_thutu_db($this->table,$id,$anhien);
	}
	function get_by_ngay($id=-1,$anhien=-1) {
		return $this->get_by_ngay_db($this->table,$id,$anhien);
	}
	function get_by_thutu_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_thutu_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_by_ngay_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_ngay_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_max_count($text="",$anhien=-1) {
        return $this->get_max_count_db($this->table,$text,$anhien);
	}
	function get_by_parent($table_parent,$field,$idparent) {
		return $this->get_by_parent_db($this->table,$table_parent,$field,$idparent);
	}
    
	function change_anhien($id) {
	   	$this->change_anhien_db($this->table,$id);
    }
	function change_anhien_list($listid) {
	   	$this->change_anhien_list_db($this->table,$listid);
    }
    
	function delete($id) {
		$this->delete_data_db($this->table,$id);
	}
	function delete_list($listid) {
		$this->delete_list_data_db($this->table,$listid);
	}
	
	function update_field($id,$field,$value,$anhien=-1) {
	   	$this->update_field_db($this->table,$id,$field,$value,$anhien);
    }
    
    /* 
    hàm update này chỉ dùng để update 1 đối tượng 
    được set dầy dủ các biến luôn cả "id" nhá
    Lưu ý: nếu ko set giá trị dầy đủ thi field nào ko set nó se~ ra null
    cho nen nếu mún update 1 filed thì nen xài hàm update_field() phía trên 
    dể update 1 field nhá  !!!!!!!
    */
	function update() {
		if ($this->id!=NULL && $this->id>0) {
			$list_field = $this->show_field_db($this->table);
			$query = "UPDATE ".$this->table." SET ";
			$flag = 0;
			foreach ($list_field as $field) {
                if ($flag == 1)
		    		$query = $query.$field[0]."='".$this->$field[0]."',";
		    	$flag = 1;
		    }
                    
		    $query = substr($query,0,strlen($query)-1);
			$query = $query." WHERE id='$this->id'";
			mysql_query($query) or die(mysql_error());
		}
    }
	
	function create() {
		// mún kiểm tra gì thì viết ở đây
		
		// code cứng không cần sửa **********************
		if ($this->thutu==-1)
			$this->thutu = $this->get_max_thutu_db($this->table)+1;
		$list_field = $this->show_field_db($this->table);
    	$query = "INSERT INTO ".$this->table." (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query.$field[0].",";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.") VALUES (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query."'".$this->$field[0]."',";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.")";
		mysql_query($query) or die(mysql_error());
		// ***********************************************
    }
	
}

// class donhang **********************************************************************************
class donhang extends db{
	private $table="donhang";
	public $id=NULL;
	public $username=NULL;
	public $thoidiemnhanhang=NULL;
	public $tennguoinhan=NULL;
	public $dtnguoinhan=NULL;
	public $diachi=NULL;
	public $tongtien=NULL;
	public $ghichu=NULL;
	public $daxuly=NULL;
	public $sessionid=NULL;
	public $datratien=NULL;
	public $url_img=NULL;
	public $url_file=NULL;
	public $ngay=NULL;
	public $thutu=-1;
	public $anhien=NULL;
	
	function dt_set_id($id) { $this->id=$id; }
	function dt_set_username($username) { $this->username=$username; }
	function dt_set_thoidiemnhanhang($thoidiemnhanhang) { $this->thoidiemnhanhang=$thoidiemnhanhang; }
	function dt_set_tennguoinhan($tennguoinhan) { $this->tennguoinhan=$tennguoinhan; }
	function dt_set_dtnguoinhan($dtnguoinhan) { $this->dtnguoinhan=$dtnguoinhan; }	
	function dt_set_diachi($diachi) { $this->diachi=$diachi; }
	function dt_set_tongtien($tongtien) { $this->tongtien=$tongtien; }
	function dt_set_ghichu($ghichu) { $this->ghichu=$ghichu; }
	function dt_set_daxuly($daxuly) { $this->daxuly=$daxuly; }	
	function dt_set_sessionid($sessionid) { $this->sessionid=$sessionid; }
	function dt_set_datratien($datratien) { $this->datratien=$datratien; }
	function dt_set_url_img($url_img) { $this->url_img=$url_img; }
	function dt_set_url_file($url_file) { $this->url_file=$url_file; }
	function dt_set_ngay($ngay) { $this->ngay=$ngay; }
	function dt_set_thutu($thutu) { $this->thutu=$thutu; }
	function dt_set_anhien($anhien) { $this->anhien=$anhien; }
	
	
	function get_by_thutu($id=-1,$anhien=-1) {
        return $this->get_by_thutu_db($this->table,$id,$anhien);
	}
	function get_by_ngay($id=-1,$anhien=-1) {
		return $this->get_by_ngay_db($this->table,$id,$anhien);
	}
	function get_by_thutu_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_thutu_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_by_ngay_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_ngay_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_max_count($text="",$anhien=-1) {
        return $this->get_max_count_db($this->table,$text,$anhien);
	}
	function get_by_parent($table_parent,$field,$idparent) {
		return $this->get_by_parent_db($this->table,$table_parent,$field,$idparent);
	}
    
	function change_anhien($id) {
	   	$this->change_anhien_db($this->table,$id);
    }
	function change_anhien_list($listid) {
	   	$this->change_anhien_list_db($this->table,$listid);
    }
    
	function delete($id) {
		$this->delete_data_db($this->table,$id);
	}
	function delete_list($listid) {
		$this->delete_list_data_db($this->table,$listid);
	}
	
	function update_field($id,$field,$value,$anhien=-1) {
	   	$this->update_field_db($this->table,$id,$field,$value,$anhien);
    }
    
    /* 
    hàm update này chỉ dùng để update 1 đối tượng 
    được set dầy dủ các biến luôn cả "id" nhá
    Lưu ý: nếu ko set giá trị dầy đủ thi field nào ko set nó se~ ra null
    cho nen nếu mún update 1 filed thì nen xài hàm update_field() phía trên 
    dể update 1 field nhá  !!!!!!!
    */
	function update() {
		if ($this->id!=NULL && $this->id>0) {
			$list_field = $this->show_field_db($this->table);
			$query = "UPDATE ".$this->table." SET ";
			$flag = 0;
			foreach ($list_field as $field) {
                if ($flag == 1)
		    		$query = $query.$field[0]."='".$this->$field[0]."',";
		    	$flag = 1;
		    }
                    
		    $query = substr($query,0,strlen($query)-1);
			$query = $query." WHERE id='$this->id'";
			mysql_query($query) or die(mysql_error());
		}
    }
	
	function create() {
		// mún kiểm tra gì thì viết ở đây
		
		// code cứng không cần sửa **********************
		if ($this->thutu==-1)
			$this->thutu = $this->get_max_thutu_db($this->table)+1;
		$list_field = $this->show_field_db($this->table);
    	$query = "INSERT INTO ".$this->table." (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query.$field[0].",";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.") VALUES (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query."'".$this->$field[0]."',";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.")";
		mysql_query($query) or die(mysql_error());
		// ***********************************************
    }
	
}

// class donhangchitiet **********************************************************************************
class donhangchitiet extends db{
	private $table="donhangchitiet";
	public $id=NULL;
	public $iddh=NULL;
	public $idsp=NULL;
	public $tensp=NULL;
	public $soluong=NULL;
	public $gia=NULL;
	public $giamgia=NULL;
	public $url_img=NULL;
	public $url_file=NULL;
	public $ngay=NULL;
	public $thutu=-1;
	public $anhien=NULL;
	
	function dt_set_id($id) { $this->id=$id; }
	function dt_set_iddh($iddh) { $this->iddh=$iddh; }
	function dt_set_idsp($idsp) { $this->idsp=$idsp; }
	function dt_set_tensp($tensp) { $this->tensp=$tensp; }
	function dt_set_soluong($soluong) { $this->soluong=$soluong; }	
	function dt_set_gia($gia) { $this->gia=$gia; }
	function dt_set_giamgia($giamgia) { $this->giamgia=$giamgia; }
	function dt_set_url_img($url_img) { $this->url_img=$url_img; }
	function dt_set_url_file($url_file) { $this->url_file=$url_file; }
	function dt_set_ngay($ngay) { $this->ngay=$ngay; }
	function dt_set_thutu($thutu) { $this->thutu=$thutu; }
	function dt_set_anhien($anhien) { $this->anhien=$anhien; }
	
	
	function get_by_thutu($id=-1,$anhien=-1) {
        return $this->get_by_thutu_db($this->table,$id,$anhien);
	}
	function get_by_ngay($id=-1,$anhien=-1) {
		return $this->get_by_ngay_db($this->table,$id,$anhien);
	}
	function get_by_thutu_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_thutu_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_by_ngay_limit($offset,$records_per_page,$text="",$anhien=-1) {
        return $this->get_by_ngay_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_max_count($text="",$anhien=-1) {
        return $this->get_max_count_db($this->table,$text,$anhien);
	}
	function get_by_parent($table_parent,$field,$idparent) {
		return $this->get_by_parent_db($this->table,$table_parent,$field,$idparent);
	}
    
	function change_anhien($id) {
	   	$this->change_anhien_db($this->table,$id);
    }
	function change_anhien_list($listid) {
	   	$this->change_anhien_list_db($this->table,$listid);
    }
    
	function delete($id) {
		$this->delete_data_db($this->table,$id);
	}
	function delete_list($listid) {
		$this->delete_list_data_db($this->table,$listid);
	}
	
	function update_field($id,$field,$value,$anhien=-1) {
	   	$this->update_field_db($this->table,$id,$field,$value,$anhien);
    }
    
    /* 
    hàm update này chỉ dùng để update 1 đối tượng 
    được set dầy dủ các biến luôn cả "id" nhá
    Lưu ý: nếu ko set giá trị dầy đủ thi field nào ko set nó se~ ra null
    cho nen nếu mún update 1 filed thì nen xài hàm update_field() phía trên 
    dể update 1 field nhá  !!!!!!!
    */
	function update() {
		if ($this->id!=NULL && $this->id>0) {
			$list_field = $this->show_field_db($this->table);
			$query = "UPDATE ".$this->table." SET ";
			$flag = 0;
			foreach ($list_field as $field) {
                if ($flag == 1)
		    		$query = $query.$field[0]."='".$this->$field[0]."',";
		    	$flag = 1;
		    }
                    
		    $query = substr($query,0,strlen($query)-1);
			$query = $query." WHERE id='$this->id'";
			mysql_query($query) or die(mysql_error());
		}
    }
	
	function create() {
		// mún kiểm tra gì thì viết ở đây
		
		// code cứng không cần sửa **********************
		if ($this->thutu==-1)
			$this->thutu = $this->get_max_thutu_db($this->table)+1;
		$list_field = $this->show_field_db($this->table);
    	$query = "INSERT INTO ".$this->table." (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query.$field[0].",";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.") VALUES (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query."'".$this->$field[0]."',";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.")";
		mysql_query($query) or die(mysql_error());
		// ***********************************************
    }
	
}

// class quang cao **********************************************************************************
class quangcao extends db{
	private $table="quangcao";
	public $id=NULL;
	public $ten_vi=NULL;
	public $ten_en=NULL;
        public $url=NULL;
	public $file=NULL;
	public $thutu=-1;
	public $anhien=NULL;
        public $ngay=NULL;
        public $vitri=NULL;
	
	function dt_set_id($id) { $this->id=$id; }
	function dt_set_ten_vi($ten_vi) { $this->ten_vi=$ten_vi; }
	function dt_set_ten_en($ten_en) { $this->ten_en=$ten_en; }
        function dt_set_url($url) { $this->url=$url; }
	function dt_set_file($file) { $this->file=$file; }
	function dt_set_thutu($thutu) { $this->thutu=$thutu; }
	function dt_set_anhien($anhien) { $this->anhien=$anhien; }
        function dt_set_ngay($ngay) { $this->ngay=$ngay; }
        function dt_set_vitri($vitri) { $this->vitri=$vitri; }
	
	
	function get_by_thutu($id=-1,$anhien=-1) {
                return $this->get_by_thutu_db($this->table,$id,$anhien);
	}
	function get_by_ngay($id=-1,$anhien=-1) {
		return $this->get_by_ngay_db($this->table,$id,$anhien);
	}
	function get_by_thutu_limit($offset,$records_per_page,$text="",$anhien=-1) {
                return $this->get_by_thutu_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_by_ngay_limit($offset,$records_per_page,$text="",$anhien=-1) {
                return $this->get_by_ngay_limit_db($this->table, $offset, $records_per_page, $text, $anhien);
	}
	function get_max_count($text="",$anhien=-1) {
                return $this->get_max_count_db($this->table,$text,$anhien);
	}
	function get_by_parent($table_parent,$field,$idparent) {
		return $this->get_by_parent_db($this->table,$table_parent,$field,$idparent);
	}
    
	function change_anhien($id) {
	   	$this->change_anhien_db($this->table,$id);
        }
	function change_anhien_list($listid) {
	   	$this->change_anhien_list_db($this->table,$listid);
        }
    
	function delete($id) {
		$this->delete_data_db($this->table,$id);
	}
	function delete_list($listid) {
		$this->delete_list_data_db($this->table,$listid);
	}
	
	function update_field($id,$field,$value,$anhien=-1) {
	   	$this->update_field_db($this->table,$id,$field,$value,$anhien);
        }
    
    /* 
    hàm update này chỉ dùng để update 1 đối tượng 
    được set dầy dủ các biến luôn cả "id" nhá
    Lưu ý: nếu ko set giá trị dầy đủ thi field nào ko set nó se~ ra null
    cho nen nếu mún update 1 filed thì nen xài hàm update_field() phía trên 
    dể update 1 field nhá  !!!!!!!
    */
	function update() {
		if ($this->id!=NULL && $this->id>0) {
			$list_field = $this->show_field_db($this->table);
			$query = "UPDATE ".$this->table." SET ";
			$flag = 0;
			foreach ($list_field as $field) {
                if ($flag == 1)
		    		$query = $query.$field[0]."='".$this->$field[0]."',";
		    	$flag = 1;
		    }
                    
		    $query = substr($query,0,strlen($query)-1);
			$query = $query." WHERE id='$this->id'";
			mysql_query($query) or die(mysql_error());
		}
    }
	
	function create() {
		// mún kiểm tra gì thì viết ở đây
		
		// code cứng không cần sửa **********************
		if ($this->thutu==-1)
			$this->thutu = $this->get_max_thutu_db($this->table)+1;
		$list_field = $this->show_field_db($this->table);
    	$query = "INSERT INTO ".$this->table." (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query.$field[0].",";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.") VALUES (";
    	$flag = 0;
    	foreach ($list_field as $field) {
    		if ($flag == 1)
    			$query = $query."'".$this->$field[0]."',";
    		$flag = 1;
    	}
    	$query = substr($query,0,strlen($query)-1);
    	$query = $query.")";
		mysql_query($query) or die(mysql_error());
		// ***********************************************
    }
	
}

?>